/*
Hdu1075
Sample Input
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
 

Sample Output
hello, i'm from mars.
i like earth!
 */
package com.yuan.algorithms.training201607;

import java.io.BufferedInputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Scanner;

/**
 * @author YouYuan
 * @contact 1265161633@qq.com
 * @date 2016年7月23日 上午9:08:04
 * @descript 哈希Map解题
 */
public class 火星文翻译成英文 {

	static Scanner sc = new Scanner(new BufferedInputStream(System.in));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));//缓冲输出流
	
	public static void main(String[] args) {
		sc.next();//接收START
		String strVal, strKey;
		HashMap<String, String> map = new HashMap<String, String>(1000);
		while (!(strVal = sc.next()).equals("END")) {
			strKey = sc.next();
			map.put(strKey, strVal);
		}
		sc.next();//接收START
		sc.nextLine();//接收多余的换行符
		String word;
		while (!(word = sc.nextLine()).equals("END")) {
			StringBuilder temp = new StringBuilder();
			for (int i = 0, len = word.length(); i < len; i++) {
				char t = word.charAt(i);
				if (t >= 'a' && t <= 'z') {
					temp.append(t);
					if (i == len - 1) {
						String result = map.get(temp);
						out.print(result == null ? temp : result);
					}
				} else {
					String result = map.get(temp.toString());
					out.print(result == null ? temp : result);
					out.print(t);
					temp = new StringBuilder();
				}
			}
			out.println();
		}
		out.flush();
	}

}
